from django.db import models
from django.utils import timezone
from organization.models import OrganizationModel
from student.models import StudentModel


# Create supervisor models here.

class AdminModel(models.Model):
    """ 管理员类 """
    admin_name = models.CharField('管理员名字', max_length=20, unique=True)
    password = models.CharField('密码', max_length=150)
    tch_num = models.CharField('职工号', max_length=15, unique=True)
    gender = models.CharField('性别', max_length=4, default='男', null=True, blank=True)
    authority = models.BooleanField('管理员类型', default=False)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)

    class Meta:
        db_table = 'supervisor'
        verbose_name = '管理员表'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.admin_name


class JobPosting(models.Model):
    """
    就业岗位表，存储企业发布的就业岗位详情。
    """
    title = models.CharField(max_length=255)  # 岗位标题
    description = models.TextField()          # 岗位描述
    requirements = models.TextField()         # 任职要求
    salary_range = models.CharField(max_length=100)  # 薪资范围
    location = models.CharField(max_length=100)       # 工作地点
    publish_date = models.DateTimeField(auto_now_add=True)  # 发布日期
    deadline = models.DateField()               # 截止日期
    organization = models.ForeignKey(OrganizationModel, on_delete=models.CASCADE)  # 与企业表关联

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'job'
        verbose_name = "就业岗位表"
        verbose_name_plural = "就业岗位表"
        ordering = ['-publish_date']


class InternshipPosting(models.Model):
    """
    实习状态表，存储学生当前的实习状态详情。
    """
    title = models.CharField(max_length=255)  # 岗位标题
    description = models.TextField()          # 岗位描述
    requirements = models.TextField()         # 任职要求
    duration = models.CharField(max_length=50)  # 实习时长
    stipend = models.CharField(max_length=100, blank=True)  # 实习补贴
    location = models.CharField(max_length=100)       # 实习地点
    start_date = models.DateField()            # 开始日期
    end_date = models.DateField()              # 结束日期
    publish_date = models.DateTimeField(auto_now_add=True)  # 发布日期
    organization = models.ForeignKey(OrganizationModel, on_delete=models.CASCADE)  # 与企业表关联
    student = models.ForeignKey(StudentModel, on_delete=models.CASCADE)  # 与学生表关联

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'internship'
        verbose_name = "实习状态表"
        verbose_name_plural = "实习状态表"
        ordering = ['-publish_date']


class InterviewSchedule(models.Model):
    """
    面试预约表，记录企业与学生的面试安排。
    """
    job_posting = models.ForeignKey(JobPosting, on_delete=models.CASCADE, null=True, blank=True)  # 关联就业岗位信息
    student = models.ForeignKey(StudentModel, on_delete=models.CASCADE)  # 与学生关联
    organization = models.ForeignKey(OrganizationModel, on_delete=models.CASCADE)  # 与企业关联
    interview_date = models.DateTimeField()  # 面试日期与时间
    interview_mode = models.CharField(max_length=50)  # 面试方式（线上/线下）
    location = models.CharField(max_length=100, blank=True)  # 面试地点（如果是线下）
    # 面试状态（待确认、已确认、取消等）字段
    # 面试状态字段，使用choices限制输入值
    STATUS_CHOICES = [
        ('pending', '待确认'),
        ('confirmed', '已确认'),
        ('cancelled', '已取消')
    ]
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    publish_date = models.DateTimeField(auto_now_add=True)  # 发布日期

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'interview'
        verbose_name = "面试预约表"
        verbose_name_plural = "面试预约表"
        ordering = ['-publish_date']
